/* Reset and base styles for consistent rendering */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Comic Sans MS', cursive, sans-serif;
    background: linear-gradient(135deg, #87CEEB 0%, #98FB98 100%);
    /* Responsive height: 450px for iframe, 90vh for full browser */
    height: 450px;
    width: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* Media query for full browser tab */
@media (min-height: 500px) {
    body {
        height: 90vh;
    }
}

/* Main container with cognitive load principles - clean, organized layout */
.container {
    width: 100%;
    height: 100%;
    padding: 15px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

/* Lyrics container with optimal spacing for readability */
.lyrics-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 600px;
}

/* Each line of lyrics with flexible layout */
.lyrics-line {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
    font-size: clamp(16px, 4vw, 24px);
    font-weight: bold;
    color: #2c3e50;
    line-height: 1.4;
    text-align: center;
}

/* Regular word styling with visual hierarchy */
.word {
    padding: 4px 8px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    white-space: nowrap;
}

/* Interactive word-image containers with touch-friendly sizing */
.word-image {
    display: inline-block;
    width: clamp(40px, 8vw, 60px);
    height: clamp(40px, 8vw, 60px);
    cursor: pointer;
    transition: transform 0.3s ease;
    /* Ensure minimum touch target size for accessibility */
    min-width: 44px;
    min-height: 44px;
}

/* Hover and focus states for better interaction feedback */
.word-image:hover {
    transform: scale(1.1);
}

.word-image:active {
    transform: scale(0.95);
}

/* 3D flip card implementation for engaging interaction */
.flip-card {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Flipped state */
.flip-card.flipped {
    transform: rotateY(180deg);
}

/* Front and back faces of flip cards */
.flip-card-front,
.flip-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transition: box-shadow 0.3s ease;
}

.flip-card-front {
    background: linear-gradient(135deg, #fff 0%, #f0f0f0 100%);
    border: 2px solid #ddd;
}

.flip-card-back {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    color: white;
    transform: rotateY(180deg);
    border: 2px solid #45a049;
}

/* Enhanced shadow on hover for depth perception */
.word-image:hover .flip-card-front,
.word-image:hover .flip-card-back {
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

/* SVG icon styling for consistent appearance */
.sun-icon,
.happy-icon,
.cloud-icon {
    width: 80%;
    height: 80%;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

/* Modified: New styling for spelled-out words with individual letters */
.spelled-word {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 2px;
    padding: 4px;
}

.letter {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    padding: 2px 4px;
    font-size: clamp(8px, 2vw, 12px);
    font-weight: bold;
    text-align: center;
    min-width: 12px;
    animation: letterPop 0.3s ease-out;
    animation-fill-mode: both;
}

/* Animation for letters appearing */
@keyframes letterPop {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Stagger the letter animations */
.letter:nth-child(1) { animation-delay: 0.1s; }
.letter:nth-child(2) { animation-delay: 0.2s; }
.letter:nth-child(3) { animation-delay: 0.3s; }
.letter:nth-child(4) { animation-delay: 0.4s; }
.letter:nth-child(5) { animation-delay: 0.5s; }
.letter:nth-child(6) { animation-delay: 0.6s; }
.letter:nth-child(7) { animation-delay: 0.7s; }
.letter:nth-child(8) { animation-delay: 0.8s; }

/* Revealed word styling with clear typography - kept for backwards compatibility */
.revealed-word {
    font-size: clamp(10px, 2.5vw, 16px);
    font-weight: bold;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Controls section with proper spacing */
.controls {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    width: 100%;
}

/* Play button with engaging design and proper touch targets */
.play-button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: linear-gradient(135deg, #FF6B6B 0%, #ee5a52 100%);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: clamp(14px, 3vw, 18px);
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    /* Ensure minimum touch target size */
    min-height: 44px;
    min-width: 120px;
}

/* Play button hover and active states */
.play-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
    background: linear-gradient(135deg, #ee5a52 0%, #FF6B6B 100%);
}

.play-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Play icon styling */
.play-icon {
    width: 16px;
    height: 16px;
}

/* Playing state styling for audio feedback */
.play-button.playing {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    animation: pulse 1.5s infinite;
}

/* Pulse animation for playing state */
@keyframes pulse {
    0% {
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    }
    50% {
        box-shadow: 0 4px 8px rgba(76, 175, 80, 0.4);
    }
    100% {
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    }
}

/* Mobile-first responsive design */
@media (max-width: 480px) {
    .container {
        padding: 10px;
    }
    
    .lyrics-line {
        gap: 6px;
    }
    
    .word-image {
        width: clamp(35px, 10vw, 50px);
        height: clamp(35px, 10vw, 50px);
    }
    
    .play-button {
        padding: 10px 20px;
        font-size: 16px;
    }
    
    /* Adjust letter sizing for mobile */
    .letter {
        font-size: clamp(6px, 1.5vw, 10px);
        padding: 1px 2px;
        min-width: 8px;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    .flip-card,
    .word-image,
    .play-button {
        transition: none;
    }
    
    .play-button.playing {
        animation: none;
    }
    
    /* Disable letter animations for reduced motion */
    .letter {
        animation: none;
    }
}

/* Focus styles for keyboard navigation */
.word-image:focus,
.play-button:focus {
    outline: 3px solid #4CAF50;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .word {
        background: white;
        border: 2px solid black;
    }
    
    .flip-card-front {
        background: white;
        border: 2px solid black;
    }
    
    .letter {
        background: white;
        border: 2px solid black;
        color: black;
    }
}